layui.use(['form','layer','jquery'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

    $(".loginBody .seraph").click(function(){
        layer.msg("这只是做个样式，至于功能，你见过哪个后台能这样登录的？还是老老实实的找管理员去注册吧",{
            time:5000
        });
    })

    //登录按钮
    form.on("submit(login)",function(data){
        $(this).text("登录中...").attr("disabled", "disabled").addClass("layui-disabled");
        var loginForm = document.forms["loginForm"];

        var accountName = loginForm.elements["Login"].value;
        var password = loginForm.elements["password"].value;
        var verifyCode = loginForm.elements["verifyCode"] ? loginForm.elements["verifyCode"].value : undefined;
        var isRemember = loginForm.elements["isRemember"] ? loginForm.elements["isRemember"].checked ? 1 : 0 : 0;

        var parms = new Object();
        parms["Login"] = accountName;
        parms["Password"] = password;
        parms["verifyCode"] = verifyCode;
        parms["isRemember"] = isRemember;
        $.post("/Admin/Login", parms, loginResponse)

        return false;
    })

    //处理登录的反馈信息
    function loginResponse(data) {
        var result = eval("(" + data + ")");
        if (result.state == 1) {
            window.location.href = "/Admin/Index";
            $(".btn-submit").html("登录成功，跳转中...");
        }
        else {

            $(".btn-submit").html("立即登录");
            $(".btn-submit").attr('disabled', false).removeClass('layui-disabled');
            //$("#verifyCode").trigger('click');//重新生成验证码
            $.layerMsg(result.message, result.state);
            GetYzcode();
        }
    }

    //表单输入效果
    //$(".loginBody .input-item").click(function(e){
    //    e.stopPropagation();
    //    $(this).addClass("layui-input-focus").find(".layui-input").focus();
    //})
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    })
})
